<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

/**
 * 配置逻辑
 */
class Join extends LogicBase
{
    
    /**
     * 获取配置列表
     */
    public function getJoinList($where = [], $field = true, $order = '', $paginate = 0)
    {
        
        return $this->modelJoin->getList($where, $field, $order, $paginate);
    }
    
    /**
     * 获取列表过滤
     */
    public function getConfigListFilter($param = [])
    {
        
        $where = [];
        
        $group = empty($param['group']) ? DATA_DISABLE : (int)$param['group'];
        
        !empty($group) && $where['group'] = $group;
        
        !empty($param['search_data']) && $where['name|number'] = ['like', '%'.(string)$param['search_data'].'%'];
        
        
        if (!empty($param['order_field'])) {
            
            
            $sort = empty($param['order_val']) ? $param['order_field'] . ' asc' : $param['order_field'] . ' desc';
        }
                
        $data['group'] = $group;
        
        return $data;
    }
    
    /**
     * 获取配置信息
     */
    public function getJoinInfo($where = [], $field = true)
    {
        
        return $this->modelJoin->getInfo($where, $field);
    }
    
    
    /**
     * 成员添加
     */
    public function joinAdd($data = [])
    {
        
        $validate_result = $this->validateJoin->scene('add')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateJoin->getError()];
        }
        
        $url = url('joinList', array('group' => $data['group'] ? $data['group'] : 0));
        
        $result = $this->modelJoin->setInfo($data);
        
        $result && action_log('新增', '新增成员，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, '成员添加成功', $url] : [RESULT_ERROR, $this->modelJoin->getError()];
    }
}
